<template>
  <view class="top-search" :style="{paddingTop: padTop}">
    <view class="location-calendar">
      <view class="location">
        <image src="../static/icon/components/location.png" mode="widthFix"></image>
        <view class="txt">星宫国际产业园-21栋2单元102室</view>
      </view>
      <view class="calendar">
        <image src="../static/icon/components/calendar.png" ></image>
        <text>{{ calendar }}</text>
      </view>
    </view>
    <view class="logo-box">
      <view class="logo"></view>
      <text>一家有温度的外卖平台</text>
    </view>
    <view class="search-box">
      <uni-icons type="left" size="20" color="#333333" @tap="goBack" v-if="page == 'search' || page == 'shop'" />
      <view class="search">
        <image src="../static/icon/components/search.png" mode="widthFix" v-if="page == 'home'" />
        <input type="text" value="" placeholder="您可以搜索想要的商品和信息服务" />
        <view class="search-btn" @tap="search"> 搜索 </view>
      </view>
     <view class="collect" v-if="page == 'shop'">
        <view class="collect-item">
          <image src="../static/icon/productDetails/collect.png"/>
          收藏
        </view>
        <view class="collect-item" @tap="complain">
          <image src="../static/icon/productDetails/jubao.png"/>投诉
        </view>
      </view>
    </view>
    <view class="shop-bg" v-if="page == 'shop'">
      <image src="../static/icon/shop-bg.png"></image>
    </view>
    <Popup ref="popupRef" />
  </view>
</template>

<script setup>
  import { onLoad } from '@dcloudio/uni-app'
  import { computed, ref } from 'vue';
  import Popup from '@/components/Popup.vue';
  const { safeAreaInsets } = uni.getSystemInfoSync()
  const popupRef = ref()
  const padTop = computed(() => {
    return safeAreaInsets.top + 13 + 'px'
  })
  const calendar = computed(() => {
    const day = new Date()
    const y = day.getFullYear()
    const m = day.getMonth()
    const d = day.getDate()
    const str = y + '年' + (m + 1>0 ? m + 1 : '0' + m + 1) + '月' +( d>0 ? d: '0' + d) + '日'
    console.log(str, 'str');
    return str
  })
  defineProps({
    page: {
      type: String,
       default: 'home'
    }
  })
  const search = () => {
    uni.navigateTo({ url: '/pages/search/search' })
    // console.log(popupRef.value.open());
  }
  const goBack = () => {
    uni.navigateBack()
  }
  const complain = () => {
    uni.navigateTo({ url: '/pages/complaintMerchant/complaintMerchant' })
  }
  onLoad((e) => {
    console.log(e, 'ppppppppp');
  })
</script>

<style lang="scss" scoped>
  .top-search {
    padding: 0 12px;
    box-sizing: border-box;
    min-height: 200px;
    width: 100%;
    background: url('../static/icon/components/home-top.png') no-repeat center center;
    background-size: 100% 100%;
    .location-calendar {
      height: 44px;
      color: #333333;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .location {
        font-size: 16px;
        image {
          width: 18px;
          margin-right: 10px;
        }
        .txt {
          display: inline-block;
          width: 176px;
          font-weight: bold;
          line-height: 19px;
          white-space:nowrap;
          text-overflow:ellipsis;
          overflow: hidden;
        }
      }
      .calendar {
        display: flex;
        align-items: center;
        width: 124px;
        height: 26px;
        border-radius: 5px;
        background-color: #FFFFFF80;
        border: 1px solid #FFFFFF;
        font-size: 12px;
        image {
          width: 24px;
          height: 24px;
        }
      }
      }
      .logo-box {
        font-size: 14px;
        color: #FF3B1EFF;
        display: flex;
        align-items: end;
        .logo {
          width: 56px;
          height: 31px;
          background: url('../static/icon/components/logo.png') no-repeat center center;
          background-size: 100% 100%;
          margin-right: 9px;
        }
        image {
          width: 56px;
          height: 31px;
      }
    }
    .search-box {
      display: flex;
      align-items: center;
      .search {
        margin-left: 6px;
        flex: 1;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 14px;
        margin-top: 6px;
        padding: 0 2px 0 10px;
        border-radius: 170px;
        border: 1px solid rgba(255,59,30,0.5);
        box-sizing: border-box;
        image {
          width: 14px;
          height: 14px;
        }
        input {
          flex: 1;
          margin: 0 10px;
        }
        .search-btn {
          color: #fff;
          width: 44px;
          height: 28px;
          font-weight: 400;
          text-align: center;
          line-height: 28px;
          background-color: #FF3B1E;
          border-radius: 139px 139px 139px 139px;
        }
      }
      .collect {
        display: flex;
        image {
          width: 20px;
          height: 20px;
        }
        .collect-item {
          display: flex;
          flex-direction: column;
          align-items: center;
          font-weight: 400;
          font-size: 10px;
          color: #333333;
          margin-left: 11px;
          &:nth-last-of-type(1) {
            margin-left: 19px;
          }
        } 
      }
    }
    .shop-bg {
      width: 100%;
      height: 140px;
      margin-top: 10px;
      border-radius: 10px;
      overflow: hidden;
      image {
        width: 100%;
        height: 100%;
      }
    }
  }
</style>